﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GISEntity;

namespace SLServiceLibrary
{
    public class WholeIndustryValue
    {

        public decimal GetWholeIndustryValue(DateTime Time, string industryType, string industryTypeName)
        {
            Server dbServer = new Server();
            //double value = 0;
            //// List<double> getwholevalue=new List<double>();
            //decimal temp = 0;
            //int industry;
            //IndusryType it = new IndusryType();
            //industry = it.GetIndustryType(industryType);

            decimal value = 0;
            decimal temp = 0;
            int industrytype;
            int industrytypename = 0;
            IndusryType it = new IndusryType();
            industrytype = it.GetIndustryType(industryType);
            industrytypename = it.GetIndustryName(industryTypeName);

            using (HnMapEntities database = new HnMapEntities(dbServer.GetConnectString()))
            {
                switch (industrytypename)
                {
                    case 1:
                        #region
                        {
                            switch (industrytype)
                            {

                                //case 9:
                                //    #region
                                //    {
                                //        var queryResult1 = from first in database.AGRICULTURALs
                                //                           where (first.TIME.Equals(Time))
                                //                           select first.AGRVALUE;

                                //        foreach (var s in queryResult1.ToList())
                                //        {
                                //            ///查到所有地市的某个行业某年的某个指标值，求和
                                //            ///
                                //            //var temp = queryResult1.Single() as CityIndustry;                              
                                //            temp += (double)s;//求单个指标的值                           
                                //        }
                                //        //value = Convert.ToDouble(temp);//queryResult1.Single()
                                //        value = temp;
                                //        //getwholevalue.Add(value);

                                //    }
                                //    #endregion
                                //    break;
                                case 10:
                                    #region
                                    {
                                        var queryResult2 = from first in database.AGRICULTURALs
                                                           where (first.TIME.Equals(Time))
                                                           select first.FARMINGVALUE;
                                        foreach (var s in queryResult2.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult2.Single());

                                    }
                                    #endregion
                                    break;
                                case 11:
                                    #region
                                    {
                                        var queryResult3 = from first in database.AGRICULTURALs
                                                           where (first.TIME.Equals(Time))
                                                           select first.FORESTYVALUE;
                                        foreach (var s in queryResult3.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;

                                        //value = Convert.ToDouble(queryResult3.Single());
                                    }
                                    #endregion
                                    break;
                                case 12:
                                    #region
                                    {
                                        var queryResult4 = from first in database.AGRICULTURALs
                                                           where (first.TIME.Equals(Time))
                                                           select first.HUSBANDRYVALUE;
                                        foreach (var s in queryResult4.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;

                                        //value = Convert.ToDouble(queryResult4.Single());
                                    }
                                    #endregion
                                    break;
                                case 13:
                                    #region
                                    {

                                        var queryResult5 = from first in database.AGRICULTURALs
                                                           where (first.TIME.Equals(Time))
                                                           select first.FISHERYVALUE;
                                        foreach (var s in queryResult5.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult5.Single());

                                    }

                                    #endregion
                                    break;
                                case 7:
                                    #region
                                    {

                                        var queryResult6 = from first in database.AGRICULTURALs
                                                           where (first.TIME.Equals(Time))
                                                           select first.SERVICEVALUE;
                                        foreach (var s in queryResult6.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult6.Single());

                                    }
                                    #endregion
                                    break;
                            }
                        }
                        #endregion
                        break;
                    case 2:
                        #region
                        {
                            switch (industrytype)
                            {

                                case 2:
                                    #region
                                    {
                                        var queryResult1 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.INDUSTRYVALUE;

                                        foreach (var s in queryResult1.ToList())
                                        {
                                            ///查到所有地市的某个行业某年的某个指标值，求和
                                            ///
                                            //var temp = queryResult1.Single() as CityIndustry;                              
                                            //求单个指标的值

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        //value = Convert.ToDouble(temp);//queryResult1.Single()
                                        value = temp;
                                        //getwholevalue.Add(value);
                                        /////////////////////////
                                        //////////////////////////
                                        //////////////////////////
                                        Console.WriteLine(value);

                                    }
                                    #endregion
                                    break;
                                case 3:
                                    #region
                                    {
                                        var queryResult2 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.BUILDINGVALUE;
                                        foreach (var s in queryResult2.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult2.Single());

                                    }
                                    #endregion
                                    break;
                                case 4:
                                    #region
                                    {
                                        var queryResult4 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.TRANSPORTVALUE;
                                        foreach (var s in queryResult4.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult4.Single());
                                    }
                                    #endregion
                                    break;
                                case 5:
                                    #region
                                    {

                                        var queryResult5 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.RETAILVALUE;
                                        foreach (var s in queryResult5.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        // value = Convert.ToDouble(queryResult5.Single());

                                    }

                                    #endregion
                                    break;
                                case 6:
                                    #region
                                    {

                                        var queryResult6 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.ESTATEVALUE;
                                        foreach (var s in queryResult6.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult6.Single());

                                    }
                                    #endregion
                                    break;

                                case 7:
                                    #region
                                    {
                                        var queryResult7 = from first in database.COUNTYINDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.SERVICEVALUE;
                                        foreach (var s in queryResult7.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult7.Single());

                                    }
                                    #endregion
                                    break;
                            }
                        }
                        #endregion
                        break;
                    case 3:
                        #region
                        {
                            switch (industrytype)
                            {

                                case 1:
                                    #region
                                    {
                                        var queryResult1 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.FIANCEVALUE;

                                        foreach (var s in queryResult1.ToList())
                                        {
                                            ///查到所有地市的某个行业某年的某个指标值，求和
                                            ///
                                            //var temp = queryResult1.Single() as CityIndustry;                              
                                            //求单个指标的值 

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        //value = Convert.ToDouble(temp);//queryResult1.Single()
                                        value = temp;
                                        //getwholevalue.Add(value);

                                    }
                                    #endregion
                                    break;
                                case 2:
                                    #region
                                    {
                                        var queryResult2 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.INDUSTRYVALUE;
                                        foreach (var s in queryResult2.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult2.Single());

                                    }
                                    #endregion
                                    break;
                                case 3:
                                    #region
                                    {

                                        var queryResult3 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.BUILDINGVALUE;
                                        foreach (var s in queryResult3.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult3.Single());

                                    }
                                    #endregion
                                    break;
                                case 4:
                                    #region
                                    {
                                        var queryResult4 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.TRANSPORTVALUE;
                                        foreach (var s in queryResult4.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult4.Single());
                                    }
                                    #endregion
                                    break;
                                case 5:
                                    #region
                                    {

                                        var queryResult5 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.RETAILVALUE;
                                        foreach (var s in queryResult5.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult5.Single());

                                    }

                                    #endregion
                                    break;
                                case 6:
                                    #region
                                    {

                                        var queryResult6 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.ESTATEVALUE;
                                        foreach (var s in queryResult6.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;

                                        //value = Convert.ToDouble(queryResult6.Single());

                                    }
                                    #endregion
                                    break;

                                case 7:
                                    #region
                                    {
                                        var queryResult7 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.SERVICEVALUE;
                                        foreach (var s in queryResult7.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult7.Single());
                                    }
                                    #endregion
                                    break;

                                case 8:
                                    #region
                                    {

                                        var queryResult8 = from first in database.INDUSTRies
                                                           where (first.TIME.Equals(Time))
                                                           select first.TOURISMVALUE;
                                        foreach (var s in queryResult8.ToList())
                                        {

                                            //temp += (double)s;
                                            temp += s;
                                        }
                                        value = temp;
                                        //value = Convert.ToDouble(queryResult8.Single());

                                    }
                                    #endregion
                                    break;
                            }
                        }
                        #endregion
                        break;
                }
                return value;
            }
        }
    }
}